External Exam Download Resources Web Applications Games Recycle Bin

Flask GET and POST

GET vs POST:

templates\template.html

<p>Type something in the text input fields:</p>

<form action="/post_input" method="POST">
  <input type="text" name="myInput" placeholder="uses POST">
  <input type="submit" value="Submit via POST">
</form>

<form action="/get_input" method="GET">
  <input type="text" name="myInput" placeholder="uses GET">
  <input type="submit" value="Submit via GET">
</form>

server.py

from flask import *
app = Flask("getting input from the user")

@app.route("/")
def main():
    return render_template("template.html")

@app.route("/post_input", methods=["POST"])
def post_input():
    message = request.form["myInput"]
    return render_template_string(message)

@app.route("/get_input", methods=["GET"])
def get_input():
    message = request.args.get("myInput")
    return render_template_string(message)
 
app.run(debug=True)